package cn.javass.dp.factorymethod.demo4;

public class Client {
    public static void main(String[] args) {
        ExportOperate ex = new ExportOperate2();
        ex.export("",3);

    }
}

interface ExportFileApi {
    boolean export(String data);
}

class ExportOperate {
    public boolean export (String data, int type) {
        ExportFileApi api = factoryMethod(type);
        return api.export(data);
    }


    protected ExportFileApi factoryMethod(int type) {
        ExportFileApi api = null;
        if (type == 1) {
            api = new ExportDB();
        } else if (type ==2 ) {
            api = new ExportXML();
        } else {
            api = null;
        }
        return api;
    }
}
class ExportOperate2 extends ExportOperate {
    @Override
    protected ExportFileApi factoryMethod(int type) {
        ExportFileApi api = null;
        if (type == 3) {
            api = new ExportText();
        } else {
            api =  super.factoryMethod(type);
        }
        return api;
    }
}



class ExportXML implements ExportFileApi {
    @Override
    public boolean export(String data) {
        System.out.println("使用XML方式导出数据");
        return false;
    }
}
class ExportDB implements ExportFileApi {

    @Override
    public boolean export(String data) {
        System.out.println("使用DB的方式来导出数据");
        return false;
    }
}
class ExportText implements ExportFileApi {

    @Override
    public boolean export(String data) {
        System.out.println("使用TEXT的方式来导出");
        return false;

    }
}


